package com.song;

import com.song.dao.SequenceDao;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * @Description: test：类描述
 * @author: songzhangyong
 * @Date: 2019/11/9 10:56
 */

public class MyBatisTest {


    public static void main(String[] args) throws IOException, InterruptedException {

        String resource = "/Users/song/Documents/D/songFile/源码解读/mybatis/mybatissong/src/main/resources/" +
                "mybatis.xml";
//        InputStream inputStream = Resources.getResourceAsStream(resource);
        InputStream inputStream = new FileInputStream(new File(resource));

        //这一步完成了mybatis.xml 文件的所有解析操作
        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(inputStream);

        factory.getConfiguration().addMapper(SequenceDao.class);

        SqlSession session = factory.openSession();


//　　我们先来看第一种形式的sql语句执行也就是SqlSession.getMapper除外的形式。这里还是以带参数的session.selectOne为例子。其实现代码为：
//        session.selectOne();

        SequenceDao sequenceDao = session.getMapper(SequenceDao.class);

        System.out.println("\r\n第一次查询");
        List query = sequenceDao.query();
        Thread.sleep(10);
        System.out.println("\r\n第二次查询");
        List query2 = sequenceDao.query();
        Thread.sleep(10);
        System.out.println("\r\n第三次查询");
        List query3 = sequenceDao.query();
        Thread.sleep(10);
        System.out.println("\r\n第四次查询");
        List query4 = sequenceDao.query();

        Thread.sleep(100);
//        System.out.println(query.get(0));
//        System.out.println(query2.get(0));
//        System.out.println("-===================");

        new Thread(() -> {
            System.out.println("\r\n另外的线程1");
            sequenceDao.query() ;
        }).start(); ;

        new Thread(() -> {
            System.out.println("\r\n另外的线程2");
            sequenceDao.query() ;
        }).start(); ;


    }



}
